;(function ($){



    $(function () {

        var currentLevel = 1;
        var previousLevel = 1;
        var offset = 5;

        $('#left').hide();

        $('.level-slide-list span').click(function () {

            var nav = $(this);
            previousLevel = currentLevel;
            currentLevel = $(this).index() + 1;


            nav.addClass('active-level').siblings('span').removeClass('active-level');
            if (offset === currentLevel && (currentLevel !== 12 )) {

                $('#levelSlideList').animate(
                    {
                        left: -$('#firstLevel').width() * (offset - 1 )
                    },
                    {
                        duration: 250, complete: function () {
                        $('#unavCursor').animate({
                            left: nav.offset().left - 0.05 * window.screen.width
                        }, 250);
                    }
                    });

                offset = offset + ( 5 - 1 );

            } else if ((offset - 4) === currentLevel && (currentLevel !== 1 )) {

                $('#levelSlideList').animate(
                    {
                        left: -$('#firstLevel').width() * (offset - 9 )
                    },
                    {
                        duration: 250, complete: function () {
                        $('#unavCursor').animate({
                            left: nav.offset().left - 0.05 * window.screen.width
                        }, 250);
                    }
                    });

                offset = offset - ( 5 - 1 );

            } else {
                $('#unavCursor').animate({
                    left: nav.offset().left - 0.05 * window.screen.width
                }, 250, function () {
                })
            }
            $('.level-info .level-item').eq(currentLevel - 1).addClass('active-level-item').siblings('.level-item').removeClass('active-level-item');

        });


        var totalPlans = 3;
        var clickItem = null;
        $('.lesson-plan .detail').on('click', function () {
            $(this).addClass('zoom-in').removeClass('zoom-out');
            $(this).siblings('div').each(function () {
                if ($(this).hasClass('zoom-in')) {
                    $(this).removeClass('zoom-in').addClass('zoom-out');
                }
            })

            if ($(this).index() === ( totalPlans - 1 )) {
                clickItem = $('.lesson-plan .detail').eq(0);
                $('.lesson-plan .detail').eq(0).remove();
                $('.lesson-plan').append(clickItem);
            }

            if ($(this).index() === 0) {
                clickItem = $('.lesson-plan .detail').eq(totalPlans - 1);
                $('.lesson-plan .detail').eq(totalPlans - 1).remove();
                $('.lesson-plan').prepend(clickItem);
            }
        })


        var timeout;
        $(document).bind("scroll", function () {

            clearTimeout(timeout);
            timeout = setTimeout(function () {

                var reviewList = $('#review');
                if ($(window).scrollTop() > reviewList.offset().top - 300) {

                    if (reviewList.css('visibility') === 'hidden') {
                        reviewList.css('visibility', 'visible');
                        reviewList.find('.item').each(function () {
                            $(this).addClass('fade-animate');
                        })
                    }
                }
            }, 10);
        });

        //初始化视频
        var player = new qcVideo.Player(
            //页面放置播放位置的元素 ID
            "videoContainer",
            {
                "file_id": "14651978969256294752",
                "app_id": "1251352524",
                "auto_play": "0",
                "width": 640,
                "height": 480,
                "remember": 1,
                "stretch_full": 1,
            });
        player.resize(650.480);

        //观看视频
        $('#viewVideo').click(function () {
            $('#videoMask').fadeIn(300);
            player.play();
        })

        //关闭视频
        $('#closeVideo').click(function () {
            player.pause();
            $('#videoMask').fadeOut(300);
        })



       // $('.apply-btn, .apply-btn-s').on('click', function () {
            var account = new Account();
            account.getRecommendation();
       // });


    })

})(window.Zepto);